/*
 * ListBox.java
 */
package xq.swing;

import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author ThorntonRP
 */
public class ListBox extends JList {

	private static final long serialVersionUID = 5531657765135207631L;
	private boolean selectionAvailable;

	public ListBox() {
		getSelectionModel().addListSelectionListener(
				new ListSelectionListener() {

					@Override
					public void valueChanged(ListSelectionEvent e) {
						setSelectionAvailable(getSelectedIndex() >= 0);
					}
				});
	}

	public boolean isSelectionAvailable() {
		return selectionAvailable;
	}

	public void setSelectionAvailable(boolean selectionAvailable) {
		boolean oldValue = this.selectionAvailable;
		boolean newValue = selectionAvailable;
		if (oldValue != newValue) {
			this.selectionAvailable = newValue;
			firePropertyChange("selectionAvailable", oldValue, newValue);
		}
	}
}
